--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Commit 81a09a2785036cb4db577c7f36540c3aecb36c6a
Parents : 6ca68b3
Author : Mark Qvist <bc7291552be7a58f361522990465165c>
Signature : T66BB85Valid, signed by author
Date : 2026-07-21T23:06:43+02:00
Added connection map telemetry plugin example
Changes
Diff
diff --git a/docs/example_plugins/connection_map.py b/docs/example_plugins/connection_map.py
new file mode 100644
index 00000000..7d97e643
--- /dev/null
+++ b/docs/example_plugins/connection_map.py
@@ -0,0 +1,69 @@
+# This example plugin creates a connection map of clients
+# connected to any BackboneInterface on your system, as
+# well as blocked IP addresses, and uses a locally stored
+# IP-to-approximate-location database, so that no IP data
+# touches external geo-location APIs. Additionally, this
+# example strips the actual IP addresses from the saved
+# telemetry data, so only the approximate locations are
+# stored and sent to downstream telemetry consumers.
+
+# This example only show the "connection" and "blocked"
+# label types, but you can additionally use "signal-P",
+# where P is the signal quality in percent, from 0 to 100.
+# In this case, Sideband will display the signal quality
+# as icons on the map. This can be useful for creating
+# coverage overviews, or for monitoring signal quality
+# of deployed links and instances.
+
+import os
+import RNS
+import IP2Location
+
+class ConnectionMapPlugin(SidebandTelemetryPlugin):
+ plugin_name = "connection_map"
+
+ def start(self):
+ RNS.log("Connection map telemetry plugin starting...")
+ self.ipdb = IP2Location.IP2Location(os.path.expanduser("IP2LOCATION-LITE-DB5.IPV6.BIN"))
+ super().start()
+
+ def stop(self):
+ super().stop()
+
+ def update_telemetry(self, telemeter):
+ try:
+ if telemeter != None:
+ rd = telemeter.read("rns_transport")
+ if rd != None:
+ telemeter.synthesize("connection_map")
+ if not rd["ifstats"]: RNS.log(f"No interfaces")
+ else:
+ ifs = rd["ifstats"]["interfaces"]; mc = 0; bc = 0
+ for iface in ifs:
+ if "parent_interface_name" in iface and iface["parent_interface_name"] != None:
+ match_str = "BackboneInterface[Client on"
+ if iface["name"].startswith(match_str):
+ mc += 1
+ parsed = iface["name"].replace(match_str, "").replace("]", "").split("/")
+ n = parsed[0][1:]; ip = parsed[1].split(":")[0]
+ ipr = self.ipdb.get_all(ip); lat = ipr.latitude; lon = ipr.longitude
+ if not (lat == 0 and lon == 0):
+ telemeter.sensors["connection_map"].add_point(lat, lon, map_name="backbone_clients",
+ altitude=0, type_label="connection", name=n)
+
+ if "blocked_ip_list" in iface:
+ for blocked_ip in iface["blocked_ip_list"]:
+ bc += 1
+ n = blocked_ip
+ ipr = self.ipdb.get_all(blocked_ip); lat = ipr.latitude; lon = ipr.longitude
+ if not (lat == 0 and lon == 0):
+ telemeter.sensors["connection_map"].add_point(lat, lon, map_name="blocked_ips",
+ altitude=0, type_label="blocked", name=n)
+
+ RNS.log(f"Added {mc} interfaces, {bc} blocked IPs")
+
+ except Exception as e:
+ RNS.log(f"Could not update connection map: {e}", RNS.LOG_ERROR)
+ RNS.trace_exception(e)
+
+plugin_class = ConnectionMapPlugin
\ No newline at end of file
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────